package com.vanguard.commons.echarts;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Title: echarts业务层数据封装类
 * @Description:
 * @Author: vanguard
 * @Version: 1.0
 * @Date: 2019/03/14
 */
public class OptionData {

    /**
     * 图表所需的数据
     */
    private List optionData;

    /**
     * 柱状图x轴（类目轴）
     */
    private List<CategoryAxis> xAxis;

    /**
     * 柱状图y轴（类目轴）
     */
    private List<CategoryAxis> yAxis;

    public List getOptionData() {
        return optionData;
    }

    public void setOptionData(List optionData) {
        this.optionData = optionData;
    }

    public List<CategoryAxis> getxAxis() {
        return xAxis;
    }

    public void setxAxis(List<CategoryAxis> xAxis) {
        this.xAxis = xAxis;
    }

    public List<CategoryAxis> getyAxis() {
        return yAxis;
    }

    public void setyAxis(List<CategoryAxis> yAxis) {
        this.yAxis = yAxis;
    }

    public List<CategoryAxis> xAxis() {
        if (this.xAxis == null) {
            this.xAxis = new ArrayList();
        }

        return this.xAxis;
    }

    public OptionData xAxis(CategoryAxis... values) {
        if (values != null && values.length != 0) {
            if (this.xAxis().size() == 2) {
                throw new RuntimeException("xAxis已经存在2个，无法继续添加!");
            } else if (this.xAxis().size() + values.length > 2) {
                throw new RuntimeException("添加的xAxis超出了最大允许的范围:2!");
            } else {
                this.xAxis().addAll(Arrays.asList(values));
                return this;
            }
        } else {
            return this;
        }
    }

    public List<CategoryAxis> yAxis() {
        if (this.yAxis == null) {
            this.yAxis = new ArrayList();
        }

        return this.yAxis;
    }

    public OptionData yAxis(CategoryAxis... values) {
        if (values != null && values.length != 0) {
            if (this.yAxis().size() == 2) {
                throw new RuntimeException("yAxis已经存在2个，无法继续添加!");
            } else if (this.yAxis().size() + values.length > 2) {
                throw new RuntimeException("添加的yAxis超出了最大允许的范围:2!");
            } else {
                this.yAxis().addAll(Arrays.asList(values));
                return this;
            }
        } else {
            return this;
        }
    }

}
